package org.andao.core.dao.helper;

import javax.persistence.Table;

import org.springframework.util.Assert;

/**
 * hibernate bean helper.
 * 
 * @author Seewo software - Marco.hu(huzhiguo@cvte.cn)
 */
public class HibernateHelper {	
		
	public final static int JOIN = 1;
	public final static int SELECT = 2;
	public final static int LAZY = 3;
	public final static int EAGER = 4;
	
	
	/**
	 * 获取指定model的表名.
	 * @param clazz
	 * @return
	 */
	public static String getEntiryOfTable(Class<?> clazz){
		Assert.notNull(clazz);		
		if(clazz.isAnnotationPresent(Table.class)){
			Table table = (Table)clazz.getAnnotation(Table.class);
			return table.name();
		}
		
		return null;
	}
	
	/**
	 * 转换IDS为符合 in('xxx','xx2')的字符.
	 * @param ids
	 * @return
	 */
	public static String convertIds2InHql(String[] ids){
		StringBuilder inHql = new StringBuilder();
		for(int i=0;i<ids.length;i++){
			inHql.append("'"+ids[i]+"',");
		}
		return inHql.toString().substring(0, inHql.toString().length()-1);
	}
	
}
